#!usr/bin/env python3
# -*- coding: utf-8 -*-

from flask import jsonify
from app.exceptions import ValidationError
from . import api as apiBP

def bad_request(msg):
	response = jsonify({"error":"bad request","message":msg})
	response.status_code = 400 # 400 请求不可用或者不一致
	return response 

def unauthorized(msg):
	response = jsonify({"error":"unauthorized","message":msg})
	response.status_code = 401 # 401 未授权
	return response

def forbidden(msg):
	response = jsonify({"error":"forbidden","message":msg})
	response.status_code = 403 # 403 阻止错误的响应处理
	return response

#处理验证错误
@apiBP.errorhandler(ValidationError) 
def validation_error(e):
	return bad_request(e.args[0])